#  这个模块专门封装各项请求，get,post

import json

class  Send:


    def send_login(self,session,username,pwd):
        url = "http://localhost:90/login/verifyLogin"

        param = {
            "username": username,
            "password": pwd
        }
        # 请求登录获取响应对象
        resp = session.get(url=url, params=param)
        resp.encoding = "utf-8"  # 修改编码集

        code = resp.status_code

        body = resp.text

        body = json.loads(body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(code, body, body.get("code"), type(body))

        return  {"code":code,"body":body}



    def  send_buy(self,session,cid,uid,pwd):
        url = "http://localhost:90/login/verifyLogin"

        param = {
            "username": "lisi",
            "password":"e10adc3949ba59abbe56e057f20f883e"
        }
        # 请求登录获取响应对象
        login_resp = session.get(url=url, params=param)
        login_resp.encoding = "utf-8"  # 修改编码集

        login_code = login_resp.status_code

        login_body = login_resp.text

        login_body = json.loads(login_body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(login_code, login_body, login_body.get("code"), type(login_body))

        buy_url = "http://localhost:90/user/userBuyChangeMoney"

        buy_param = {
            "changeMoneyId": cid,
            "userId": uid,
            "passWord": pwd
        }
        #   get(key-value;params)  post(key:value,data)   post(json,json)
        resp = session.post(url=buy_url, data=buy_param)

        resp.encoding = "utf-8"  # 修改编码集

        code = resp.status_code

        body = resp.text
        body = json.loads(body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(code, body, body.get("code"), type(body))

        return  {"code":code,"body":body}


    def send_register(self,session,username,password):
        url = "http://localhost:90/login/register"

        data = {
            "username": username,
            "password": password
        }
        # 请求登录获取响应对象
        resp = session.post(url=url, data=data)
        resp.encoding = "utf-8"  # 修改编码集

        code = resp.status_code

        body = resp.text

        body = json.loads(body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(code, body, body.get("code"), type(body))

        return  {"code":code,"body":body}


    def send_Change_money(self,session,changeMoneyId,ID,passWord):
        url = "http://localhost:90/user/userBuyChangeMoney"

        data = {
            "changeMoneyId": changeMoneyId,
            "Id": ID,
            "passWord": passWord
        }
        # 请求登录获取响应对象
        resp = session.post(url=url, data=data)
        resp.encoding = "utf-8"  # 修改编码集

        code = resp.status_code

        body = resp.text

        body = json.loads(body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(code, body, body.get("code"), type(body))

        return  {"code":code,"body":body}


    def  send_buy_TermFinancial(self,session,cid,uid,pwd):
        url = "http://localhost:90/login/verifyLogin"

        param = {
            "username": "lisi",
            "password":"e10adc3949ba59abbe56e057f20f883e"
        }
        # 请求登录获取响应对象
        login_resp = session.get(url=url, params=param)
        login_resp.encoding = "utf-8"  # 修改编码集

        login_code = login_resp.status_code

        login_body = login_resp.text

        login_body = json.loads(login_body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(login_code, login_body, login_body.get("code"), type(login_body))

        buy_url = "http://localhost:90/user/buyTermFinancial"

        buy_param = {
            "termFinancialId": cid,
            "userId": uid,
            "passWord": pwd
        }
        #   get(key-value;params)  post(key:value,data)   post(json,json)
        resp = session.post(url=buy_url, data=buy_param)

        resp.encoding = "utf-8"  # 修改编码集

        code = resp.status_code

        body = resp.text
        body = json.loads(body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(code, body, body.get("code"), type(body))

        return  {"code":code,"body":body}




    def  send_buy_FundProduct(self,session,cid,uid,pwd):
        url = "http://localhost:90/login/verifyLogin"

        param = {
            "username": "lisi",
            "password":"e10adc3949ba59abbe56e057f20f883e"
        }
        # 请求登录获取响应对象
        login_resp = session.get(url=url, params=param)
        login_resp.encoding = "utf-8"  # 修改编码集

        login_code = login_resp.status_code

        login_body = login_resp.text

        login_body = json.loads(login_body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(login_code, login_body, login_body.get("code"), type(login_body))

        buy_url = "http://localhost:90/user/buyFundProduct"

        buy_param = {
            "fundProductId": cid,
            "userId": uid,
            "passWord": pwd
        }
        #   get(key-value;params)  post(key:value,data)   post(json,json)
        resp = session.post(url=buy_url, data=buy_param)

        resp.encoding = "utf-8"  # 修改编码集

        code = resp.status_code

        body = resp.text
        body = json.loads(body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(code, body, body.get("code"), type(body))

        return  {"code":code,"body":body}


    def  send_applyLoan(self,session,amount,term,rate):
        url = "http://localhost:90/login/verifyLogin"

        param = {
            "username": "lisi",
            "password":"e10adc3949ba59abbe56e057f20f883e"
        }
        # 请求登录获取响应对象
        login_resp = session.get(url=url, params=param)
        login_resp.encoding = "utf-8"  # 修改编码集

        login_code = login_resp.status_code

        login_body = login_resp.text

        login_body = json.loads(login_body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(login_code, login_body, login_body.get("code"), type(login_body))

        buy_url = "http://localhost:90/user/applyLoan"

        buy_param = {
            "amount": amount,
            "term": term,
            "rate": rate
        }
        #   get(key-value;params)  post(key:value,data)   post(json,json)
        resp = session.post(url=buy_url, data=buy_param)

        resp.encoding = "utf-8"  # 修改编码集

        code = resp.status_code

        body = resp.text
        body = json.loads(body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(code, body, body.get("code"), type(body))

        return {"code": code, "body": body}

    def send_addBankCard(self, session,cardbank,card_type,cardnum):
        url = "http://localhost:90/login/verifyLogin"

        param = {
            "username": "lisi",
            "password": "e10adc3949ba59abbe56e057f20f883e"
        }
        # 请求登录获取响应对象
        login_resp = session.get(url=url, params=param)
        login_resp.encoding = "utf-8"  # 修改编码集

        login_code = login_resp.status_code

        login_body = login_resp.text

        login_body = json.loads(login_body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(login_code, login_body, login_body.get("code"), type(login_body))

        add_url = "http://localhost:90/user/addBankCard"

        add_param = {
            "cardbank": cardbank,
            "type": card_type,
            "cardnum": cardnum
        }
        #   get(key-value;params)  post(key:value,data)   post(json,json)
        resp = session.post(url=add_url, data=add_param)

        resp.encoding = "utf-8"  # 修改编码集

        code = resp.status_code

        body = resp.text
        body = json.loads(body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(code, body, body.get("code"), type(body))

        return {"code": code, "body": body}


    def send_updateBankCard(self, session,cardbank,card_type,cardnum):
        url = "http://localhost:90/login/verifyLogin"

        param = {
            "username": "lisi",
            "password": "e10adc3949ba59abbe56e057f20f883e"
        }
        # 请求登录获取响应对象
        login_resp = session.get(url=url, params=param)
        login_resp.encoding = "utf-8"  # 修改编码集

        login_code = login_resp.status_code

        login_body = login_resp.text

        login_body = json.loads(login_body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(login_code, login_body, login_body.get("code"), type(login_body))

        add_url = "http://localhost:90/user/updateBankCard/4"

        add_param = {
            "cardbank": cardbank,
            "type": card_type,
            "cardnum": cardnum
        }
        #   get(key-value;params)  post(key:value,data)   post(json,json)
        resp = session.put(url=add_url, data=add_param)

        resp.encoding = "utf-8"  # 修改编码集

        code = resp.status_code

        body = resp.text
        body = json.loads(body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(code, body, body.get("code"), type(body))

        return {"code": code, "body": body}



    def send_updatepwd(self, session,id,oldpwd,newpwd):
        url = "http://localhost:90/login/verifyLogin"

        param = {
            "username": "lisi",
            "password": "e10adc3949ba59abbe56e057f20f883e"
        }
        # 请求登录获取响应对象
        login_resp = session.get(url=url, params=param)
        login_resp.encoding = "utf-8"  # 修改编码集

        login_code = login_resp.status_code

        login_body = login_resp.text

        login_body = json.loads(login_body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(login_code, login_body, login_body.get("code"), type(login_body))

        add_url = "http://localhost:90/user/updateBankCard/4"

        add_param = {
            "id": id,
            "oldpwd": oldpwd,
            "nwepwd": newpwd
        }
        #   get(key-value;params)  post(key:value,data)   post(json,json)
        resp = session.put(url=add_url, data=add_param)

        resp.encoding = "utf-8"  # 修改编码集

        code = resp.status_code

        body = resp.text
        body = json.loads(body)  # json.loads() str --> dict    json.dumps()  dict --> str

        print(code, body, body.get("code"), type(body))

        return {"code": code, "body": body}













